<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="时间范围">
          <el-date-picker
              v-model="value1"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="handleDateChange">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="formLoading" :data="listData.list" style="width: 100%" size="small" highlight-current-row>
        <el-table-column prop="id" label="ID" min-width="90"/>
        <el-table-column prop="typeName" label="获取方式" min-width="150"/>
        <el-table-column prop="name" label="描述" min-width="150"/>
        <el-table-column v-if="type===1||type===3" prop="voucher"
                         label="益联券" min-width="100"/>
        <el-table-column v-if="type===2" prop="integral"
                         label="益积分" min-width="100"/>
        <el-table-column prop="createTime" label="记录时间" min-width="100"/>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[10,20,50,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import {detail, dataSummary, getUserList} from "@/api/user";

export default {
  components: {},
  props: {
    id: {
      default: null
    },
    type: {
      default: null
    }
  },
  data() {
    return {
      value1:'',
      formLoading: false,
      listData: {list: [], count: 0},
      listPram: {
        page: 1,
        limit: 20,
        type: '',
        userid: '',
        beginTime: '',
        endTime: ''
      },
    }
  },
  mounted() {
    if (this.id) {
      this.getList();
    }
  },
  methods: {
    handleDateChange(value) {
      this.listPram.beginTime = value[0];
      this.listPram.endTime = value[1];
    },
    getList() {
      this.listPram.userid = this.id;
      this.listPram.type = this.type;
      getUserList(this.listPram).then(res => {
        this.listData = res
      }).finally(() => {
        this.formLoading = false;
      })
    },
    close() {
      this.$emit('hideEditDialog')
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery() {
      this.value1=''
      this.listPram.page = 1;
      this.listPram.limit = 20;
      this.listPram.endTime = '';
      this.listPram.beginTime = '';

      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep {
  .el-upload {
  }
}

.img {
  width: 80px;
  height: 80px;
  border-radius: 100px;
}
</style>
